package com.imti.controller;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.imti.Api.CommonResult;
import com.imti.entity.Hospital;
import com.imti.service.HospitalService;
import com.imti.service.RedisService;
import com.imti.utils.RandomUtil;
import com.imti.utils.Sample;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * (Hospital)表控制层
 *
 * @author makejava
 * @since 2023-02-01 09:51:32
 */
@RestController
@RequestMapping("hospital")
public class HospitalController {
    /**
     * 服务对象
     */
    @Resource
    private HospitalService hospitalService;

    @Resource
    private RedisService redisService;

    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping
    public CommonResult<Hospital> selectAll() {

        return CommonResult.success(hospitalService.getById(1));
    }

    /**
     * 发送验证码，1、保存redis数据库 2、发送到手机 3、设置验证码过期时间
     *
     * @param phone
     * @return json
     */
    @PostMapping ("/sendValideCode")
    public CommonResult sendValideCode(String phone) throws Exception {

        // 生成随机数
        String code = String.valueOf(RandomUtil.random());
        redisService.set(phone, code);
        Sample.shortMessage(phone, code);//发送手机验证码
        if (redisService.get(phone) != null) {
            System.out.println(code);
            redisService.expire(phone,  60 * 5);
            return CommonResult.success("验证码发送成功");
        } else {
            return CommonResult.failed("验证码发送失败");
        }
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     *//*
    @GetMapping("{id}")
    public R selectOne(@PathVariable Serializable id) {
        return success(this.hospitalService.getById(id));
    }

    *//**
     * 新增数据
     *
     * @param hospital 实体对象
     * @return 新增结果
     *//*
    @PostMapping
    public R insert(@RequestBody Hospital hospital) {
        return success(this.hospitalService.save(hospital));
    }

    *//**
     * 修改数据
     *
     * @param hospital 实体对象
     * @return 修改结果
     *//*
    @PutMapping
    public R update(@RequestBody Hospital hospital) {
        return success(this.hospitalService.updateById(hospital));
    }

    *//**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     *//*
    @DeleteMapping
    public R delete(@RequestParam("idList") List<Long> idList) {
        return success(this.hospitalService.removeByIds(idList));
    }*/
}

